from manim import *
import numpy as np


class MObjectExample(Scene):
    def construct(self):
        p1 = np.array([-1,-1,0])
        p2=np.array([1,-1,0])
        p3=np.array([1,1,0])
        p4=np.array([-1,1,0])
        a = Line(start=p1, end=p2)\
            .append_points(new_points=Line(start=p2, end=p3).points)\
            .append_points(new_points=Line(start=p3, end=p4).points)

        point_start = a.get_start()
        point_end = a.get_end()
        point_center = a.get_center()

        self.add(Text(f"a.get_start(): {np.round(a=point_start,decimals=2).tolist()}",
                      font_size=24)
                 .to_edge(edge=UR).set_color(color=YELLOW))

        self.add(Text(f"a.get_end(): {np.round(a=point_end,decimals=2).tolist()}",
                      font_size=24)
                 .next_to(mobject_or_point=self.mobjects[-1], direction=DOWN)
                 .set_color(color=RED))

        self.add(Text(f"a.get_center(): {np.round(a=point_center,decimals=2).tolist()}",
                      font_size=24)
                 .next_to(self.mobjects[-1], direction=DOWN)
                 .set_color(color=GREEN))


        self.add(Dot(point=a.get_start()).set_color(color=YELLOW).scale(scale_factor=2))
        self.add(Dot(point=a.get_end()).set_color(color=RED).scale(scale_factor=2))
        self.add(Dot(point=a.get_top()).set_color(color=GREEN_A).scale(scale_factor=2))
        self.add(Dot(point=a.get_bottom()).set_color(color=GREEN_D).scale(scale_factor=2))
        self.add(Dot(point=a.get_center()).set_color(color=BLUE).scale(scale_factor=2))
        self.add(Dot(point=a.point_from_proportion(alpha=0.5)).set_color(color=ORANGE).scale(scale_factor=2))
        self.add(*[Dot(x) for x in a.points])
        self.add(a)